/**
 * @desc
 * @author  刘贺[of2220]
 * @company qianmi.com
 * @Date    2017/2/10
 */
"use strict";

import $http from 'webutil/ajax';
import Promise from 'webutil/promise';

export default class ImageInfoApi {
    static saveImage({pid, name, src, des, keyword = [], fileSize = '', imgSize = ''}) {
        return new Promise((resolve, reject) => {
            $http.post('/relatedImgInfo/saveImage', {pid, name, src, des, keyword, fileSize, imgSize}).then((res) => {
                res.result === 'ok' ? resolve(res.data) : reject(res.message)
            }, (err) => {
                reject(err);
            });
        });
    }

    static deleteImage({id}) {
        return new Promise((resolve, reject) => {
            $http.post('/relatedImgInfo/deleteImage', {id}).then((res) => {
                res.result === 'ok' ? resolve(res.data) : reject(res.message)
            }, (err) => {
                reject(err);
            });
        });
    }

    static updateImageInfo({id, imgInfo}) {
        return new Promise((resolve, reject) => {
            $http.post('/relatedImgInfo/updateImageInfo', {id, 'imgInfo':JSON.stringify(imgInfo)}).then((res) => {
                res.result === 'ok' ? resolve(res.data) : reject(res.message)
            }, (err) => {
                reject(err);
            });
        });
    }

    static getImageList({pid, pageNum, pageSize}) {
        return new Promise((resolve, reject) => {
            $http.post('/relatedImgInfo/getImageList', {pid, pageNum, pageSize}).then((res) => {
                res.result === 'ok' ? resolve(res.data) : reject(res.message)
            }, (err) => {
                reject(err);
            });
        });
    }
}